package games.ThunderFighter;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 2016/12/13.
 */
public class Enemy implements ActionListener {

    static JButton enemy;
    static Timer time1,attack;
    static int x;
    static int y=-40;
    static int HP=5;
    Bullet equipment;

    Enemy(GameWindow window){
        enemy=new JButton("敌机");
        window.panel.add(enemy);
        enemy.addActionListener(this);
        x=(int)(Math.random()*340/10)*10;
        enemy.setBounds(x,y,60,30);
        equipment=new Bullet(window);
        equipment.enemyBullet();
        time1=new Timer(20,this);
        attack=new Timer(1300,this);
    }

    public static void getEnemy(){
        time1.start();
        attack.start();
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==time1){                               //对应的线程调用对应方法
            y=y+1;
            enemy.setBounds(x,y,60,30);
            if(y>650){
                y=-40;
                x=(int)(Math.random()*340/10)*10;
                enemy.setBounds(x,y,60,30);
            }
        }
        if(e.getSource()==attack){                               //对应的线程调用对应方法
            Bullet.enemyBulletAttack(x,y);
        }
    }
}
